package sparkSql

import org.apache.spark.sql.SQLContext
import org.apache.spark.{SparkConf, SparkContext}

object SparkSql {
  case class personObj(name: String,age:Int,height:Int)//相当于get,set
  def main(args: Array[String]): Unit = {
    System.setProperty("hadoop.home.dir", "E:\\software\\hadoop-2.7.3")
    System.setProperty("HADOOP_USER_NAME", "root")

    // 1)
    val conf = new SparkConf().setMaster("local[*]").setAppName("helloSql")
    val sc = new SparkContext(conf)
    //2)
    val sqlCon = new SQLContext(sc)

    sc.setLogLevel("error")

    //rdd
    val personList = List(personObj("xiaowang",18,178),personObj("xiaolan",20,170),personObj("Cynrain",21,172))
    val personRdd = sc.parallelize(personList)



    //3)
    import sqlCon.implicits._
    val personDF = personRdd.toDF
    personDF.show()


    personDF.registerTempTable("person")
    sqlCon.sql("select * from person where age>=20").show()

    personDF.write.save("E:\\SparkSqlData\\4")







  }
}


